﻿using System;
using System.IO;
using System.Reflection;

namespace Dotnet.Utils.Utility
{
    public static class PathUtil
    {
        public static string GetFullPath(string pathName)
        {
            string fullPath;
            if (pathName.Contains(Path.DirectorySeparatorChar))
            {
                fullPath = Path.GetFullPath(pathName);
            }
            else
            {
                string text = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath);
                while (!Directory.Exists(Path.Combine(Path.GetFullPath(text), pathName)))
                {
                    text = Path.Combine(text, "..");
                }
                fullPath = Path.GetFullPath(Path.Combine(Path.GetFullPath(text), pathName));
            }
            return fullPath;
        }

        public static string GetStartupPath()
        {
            return new FileInfo(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath).DirectoryName;
        }
    }
}